package com.hook.test2;

import android.content.Context;
import android.content.SharedPreferences;
import android.widget.TextView;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;


public class TargetHook implements IXposedHookLoadPackage {
    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        XposedBridge.log(lpparam.packageName);
        findAndHookMethod("com.stub.StubApp", lpparam.classLoader, "ᵢˋ", Context.class, new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                //获取到360的Context对象，通过这个对象来获取classloader
                Context context = (Context) param.args[0];
                //获取360的classloader，之后hook加固后的代码就使用这个classloader
                ClassLoader classLoader = context.getClassLoader();
                //替换classloader,hook加固后的真正代码

                findAndHookMethod("mylibrary.myconfig.MyConfig", classLoader, "getAppName", new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param)
                            throws Throwable {
                        XposedBridge.log("getAppName:"+param.getResult().toString());

                    }
                });
                findAndHookMethod("mylibrary.myconfig.MyConfig", classLoader, "getQiyuId", new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param)
                            throws Throwable {
                        XposedBridge.log("getQiyuId:"+param.getResult().toString());

                    }
                });
                findAndHookMethod("mylibrary.myconfig.MyConfig", classLoader, "getYUNSCkey", new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param)
                            throws Throwable {
                        XposedBridge.log("getYUNSCkey:"+param.getResult().toString());

                    }
                });
                findAndHookMethod("mylibrary.myconfig.MyConfig", classLoader, "getYUNSCSginkey", new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param)
                            throws Throwable {
                        XposedBridge.log("getYUNSCSginkey:"+param.getResult().toString());

                    }
                });
                findAndHookMethod("mylibrary.encryption.HmacSHA256", classLoader, "getHmacSHA256",
                        String.class,
                        String.class,
                        new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

                        XposedBridge.log("getHmacSHA256:"+param.args[0].toString() + "----" + param.args[1].toString());
                    }
                });
                findAndHookMethod("mylibrary.encryption.XXTEA", classLoader, "encryptToBase64String",
                        String.class,
                        String.class,
                        new XC_MethodHook() {
                            @Override
                            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

                                XposedBridge.log("encryptToBase64String:"+param.args[0].toString() + "----" + param.args[1].toString());
                            }
                        });

            }
        });
    }
}
